import pytest
import requests

from data.read_data import read_tpshopLogin
from scripts.hm02_api import TpshopLoginAPI
from scripts.hm03_assert import Tpshopcommon


class TestTpshopLogin:
    # 添加类属性
    session = None

    # 所有测试执行前定义session
    def setup_class(self):
        self.session = requests.session()

    # 获取验证码（每个测试执行前）
    def setup(self):
        TpshopLoginAPI.get_verify_code(self.session)

    # 测试用例1：登录成功
    @pytest.mark.parametrize("username,password,verify_code,state_code,code,msg",read_tpshopLogin())
    def test01_login_success(self, username, password, verify_code, state_code, code, msg):
        login_data = {"username": username, "password": password, "verify_code": verify_code}
        login_result = TpshopLoginAPI.login(self.session, login_data)
        # 断言
        Tpshopcommon.common_assert(login_result, state_code, code, msg)
